/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.actions.marca;

import com.mapping.Marca;
import com.opensymphony.xwork2.ActionSupport;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
/**
 *
 * @author PARDmx
 */

@Namespace(value = "/")
@Action(value = "modificarMarcaP", results = {
    @Result(name = "success", location = "/GestionMarcas/resultadoMarca.jsp")})
public class ModificarMarcaAction extends ActionSupport{
    private String mensaje = "La actualizacion se realizo correctamente: ";
    private int idMarca;
    private String Nmarca;
    private Marca marca;
    
    @Override
    public String execute(){     
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("inventarios");
        EntityManager em = emf.createEntityManager();
        EntityTransaction tx = em.getTransaction();
        tx.begin();                     
        marca= em.getReference(Marca.class,idMarca);
        marca.setMarca(Nmarca);
        em.merge(marca);
        em.flush();
        tx.commit();
        em.close();             
        return SUCCESS;
    }    

    public String getMensaje() {
        return mensaje;
    }

    public Marca getMarca() {
        return marca;
    }

    public void setIdMarca(int idMarca) {
        this.idMarca = idMarca;
    }

    public void setNmarca(String Nmarca) {
        this.Nmarca = Nmarca;
    }
    
    
}
